package javafx.MyDemo;

import com.sun.prism.paint.Color;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Background;
import javafx.scene.layout.Border;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.BorderStroke;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.TilePane;
import javafx.stage.Stage;

public class LockPanel extends Application {
	Button start =null;
	Button stop =null;
	StackPane stack = null;
	AnchorPane glassPane = null;
	
	public void start(Stage stage) throws Exception {
		BorderPane root = new BorderPane();
		
		HBox hBox = new HBox();
		hBox.setSpacing(10);
		start = new Button("start");
		stop = new Button("stop");
		hBox.getChildren().add(start);
		hBox.getChildren().add(stop);
		
		root.setTop(hBox);
		hBox.setPadding(new Insets(10));
		hBox.setPrefSize(0, 40);
		hBox.setAlignment(Pos.CENTER);
		
		Button btn = new Button("testBtn");
		stack = new StackPane();
		
		
		AnchorPane anchor = new AnchorPane();
		anchor.getChildren().add(btn);
		anchor.setBottomAnchor(btn, 15D);
		anchor.setRightAnchor(btn, 15D);
		stack.getChildren().add(anchor);
		anchor.setStyle("-fx-background-color: #FFFFFF; ");
		
		root.setCenter(stack);

		Scene scene = new Scene(root,300,300);
		stage.setScene(scene);
		
		addAction();
		
		stage.show();
	}
	
	public void lockPanel(){
		glassPane = new AnchorPane();
		
		ProgressIndicator pin = new ProgressIndicator();
        pin.setProgress(-1f);
        pin.setPrefSize(70	, 70);
        pin.setStyle("-fx-opacity:1.0");
        double w = 300;  // stack.getPrefWidth();
        double h = 200; //stack.getPrefHeight();
        
		
        double x = (w-70)/2;
        double y = (h-70)/2;
        
        glassPane.getChildren().add(pin);
        glassPane.setTopAnchor(pin, y);
        glassPane.setLeftAnchor(pin, x);
        
        glassPane.setPrefSize(w, h);
        glassPane.setStyle("-fx-background-color: #000000;-fx-opacity:0.4");
        
		stack.getChildren().add(glassPane);
	}
	
	public void releasePanel(){
		
		stack.getChildren().remove(glassPane);
		glassPane = null;
	}
	
	public void addAction(){
		start.setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent arg0) {
				lockPanel();
			}
		});
		
		stop.setOnAction(new EventHandler<ActionEvent>() {
			
			public void handle(ActionEvent arg0) {
				releasePanel();
			}
		});
	}
	
	public static void main(String[] args) {
		launch(null);
	}
}
